
package com.superjson.showpro.entity;

import com.superjson.showpro.base.BaseObj;
import com.superjson.showpro.shared.enums.PictureTypeEnum;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
import javax.persistence.Transient;
import java.io.Serializable;

/**
 * Created By zby on 15:59 2019/6/22
 * 图片实体类
 */
@Entity
@Table(name = "sp_picture")
@AllArgsConstructor
@NoArgsConstructor
@Data
public class Picture extends BaseObj implements Serializable{

    private static Logger logger = LoggerFactory.getLogger(Picture.class);

    //新生成的唯一图片名称
    @Column(name = "name", length = 300, nullable = false)
    private String name;

    //图片原始名字
    @Column(name = "original_name", length = 125)
    private String originalName;

    //图片路径
    @Column(name = "picture_url", length = 300)
    private String pictureUrl;

    //  图片大小
    @Column(length = 8)
    private Integer size;

    /**
     * 图片所属类型
     * user_logo:用户头像
     */
    @Column(name = "picture_type", length = 58)
    private PictureTypeEnum pictureType;


    @Column(length = 6)
    private Integer width;

    @Column(length = 6)
    private Integer height;

    //照片描述
    @Column(name = "description", length = 255)
    private String description;


    //返回以长边为标准
    @Transient
    public String getFormatPicSize(int formatHeight, int formatWidth) {
        try {
            if (height / width > formatHeight / formatWidth) {
                return "height='" + formatHeight + "'";
            } else {
                return "width='" + formatWidth + "'";
            }
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
            return "";
        }
    }
}
